package com.lagou.edu.email.service.impl;

import com.lagou.edu.api.IEmailSendService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * created by kirito at 2020/7/19
 */
@Service
@RefreshScope
public class EmailSendServiceImpl implements IEmailSendService {

    @Value("${spring.mail.username}")
    private String from;
    @Value("${spring.mail.subject}")
    private String subject;

    @Autowired
    private JavaMailSender javaMailSender;

    @Override
    public void sendEmail(String email, Object data) throws Exception {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(email);
        message.setSubject(subject);
        message.setText(data.toString());
        javaMailSender.send(message);
    }
}
